// 通过Injectable注解的方式 使得父组件可以通过constructor进行实例化
import { Injectable } from '@nestjs/common';
// Repository为实体数据库
import { IsNull, Like, Not, Repository } from 'typeorm';
// InjectRepository 把我们的东西注入都仓库里面
import { InjectRepository } from '@nestjs/typeorm';
// 在引入实体类
import SysTest from '../../entities/test/sys-test.entity';
@Injectable()
export class AppService {
  constructor(
    @InjectRepository(SysTest) private readonly systest: Repository<SysTest>, // private redisService: RedisService, // @Inject(ROOT_ROLE_ID) private rootRoleId: number, // private roleService: SysRoleService, // private adminWSService: AdminWSService,
  ) {}

  addTest() {
    const data = new SysTest();
    data.key = '11';
    data.name = '鹏1';
    data.remark = 'remark1';
    data.value = '郅1';
    return this.systest.save(data);
    // 删除是delete 一个参数
    // update 两个参数 一个是id 一个是要修改的dat
  }
  deleteTest(id: number) {
    return this.systest.delete(id);
  }
  updateTest(id: number) {
    const data = new SysTest();
    data.key = '11';
    data.name = '鹏1';
    return this.systest.update(id, data);
  }
  // 根据传递进来的name 进行模糊查询
  getTetsName(name: string) {
    return this.systest.find({
      where: {
        name: Like(`%${name}%`),
      },
    });
  }
}
